<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function cal(type) {
				console.log('cal');
				var num1 = parseFloat(document.getElementById('num1Id').value);
				var num2 = parseFloat(document.getElementById('num2Id').value);
				
				//eval '2+3'  '2-3'  '2*3'
				var result = eval(num1 + type + num2);
				/* var result;
				switch (type){
					case '+':
						result = num1 + num2;
						break;
					case '-':
						result = num1 - num2;
						break;
					default:
						break;
				} */
				var resultObj = document.getElementById('resultId');
				resultObj.value = result;
			}
			
			function add() {
				var num1 = parseFloat(document.getElementById('num1Id').value);
				var num2 = parseFloat(document.getElementById('num2Id').value);
				
				var result = num1 + num2;
				var resultObj = document.getElementById('resultId');
				resultObj.value = result;
			}
			
			function sub() {
				var num1 = parseFloat(document.getElementById('num1Id').value);
				var num2 = parseFloat(document.getElementById('num2Id').value);
				
				var result = num1 - num2;
				var resultObj = document.getElementById('resultId');
				resultObj.value = result;
			}
			
			function mul() {
				var num1 = parseFloat(document.getElementById('num1Id').value);
				var num2 = parseFloat(document.getElementById('num2Id').value);
				
				var result = num1 * num2;
				var resultObj = document.getElementById('resultId');
				resultObj.value = result;
			}
			
			function div() {
				var num1 = parseFloat(document.getElementById('num1Id').value);
				var num2 = parseFloat(document.getElementById('num2Id').value);
				
				var result = num1 / num2;
				var resultObj = document.getElementById('resultId');
				resultObj.value = result;
			}
		</script>
	</head>
	<body>
		<table>
			  <tr>
				 <td><img src="" /></td>
				 <td>购物简易计算器</td>
			  </tr>
			  <tr>
				 <td>第一个数</td>
				 <td>
					 <input type="text" id="num1Id" />
				 </td>
			  </tr>
			  <tr>
				 <td>第二个数</td>
				 <td>
					 <input type="text" id="num2Id" />
				 </td>
			  </tr>
			  <tr>
				 <td>
					  <input type="button" value=" + " onclick="cal('+')"/>
				 </td>
				 <td>
					 <input type="button" value=" - " onclick="cal('-')"/>
					 <input type="button" value=" * " onclick="mul()"/>
					 <input type="button" value=" / " onclick="div()"/>
				 </td>
			  </tr>
			  <tr>
				 <td>计算结果</td>
				 <td>
					 <input  type="text" id="resultId" />
				 </td>
			  </tr>
		  </table>
		  
		  
	</body>
</html>
